export const mustWriteDom = (h) => {
  return h('span', {
    class: 'Error'
  }, '必填')
}

export const noMustWriteDom = (h) => {
  return h('span', {
    class: 'Green'
  }, '选填')
}

export const apiThead = (vm, apiOption = {}) => [
  {
    title: '属性',
    key: 'name',
    width: apiOption.nameWidth || 100,
    align: 'center'
  },
  {
    title: '说明',
    key: 'desc',
    render: (h, params) => {
      const { desc } = params.row

      if (typeof desc === 'string') {
        return h('span', {}, desc)
      }
      return desc(h, vm)
    }
  },
  {
    title: '传入参数类型',
    key: 'optionType',
    width: 120,
    align: 'center',
    render: (h, params) => {
      const { optionType } = params.row

      if (typeof optionType === 'string') {
        return h('span', {}, optionType)
      }
      return optionType(h, vm)
    }
  },
  {
    title: '默认值',
    key: 'defaultValue',
    width: 100,
    align: 'center'
  }
]

export const methodsThead = (vm, methodsOption = {}) => [
  {
    title: '方法名',
    key: 'name',
    width: methodsOption.nameWidth || 100,
    align: 'center'
  },
  {
    title: '说明',
    key: 'desc',
    render: (h, params) => {
      const { desc } = params.row

      if (typeof desc === 'string') {
        return h('span', {}, desc)
      }
      return desc(h, vm)
    }
  },
  {
    title: '参数',
    key: 'parameter',
    width: 100,
    align: 'center'
  }
]

export const emitThead = (vm, emitOption = {}) => [
  {
    title: '事件名',
    key: 'name',
    width: emitOption.nameWidth || 100,
    align: 'center'
  },
  {
    title: '说明',
    key: 'desc',
    render: (h, params) => {
      const { desc } = params.row

      if (typeof desc === 'string') {
        return h('span', {}, desc)
      }
      return desc(h, vm)
    }
  },
  {
    title: '返回值',
    key: 'returnValue',
    width: 100,
    align: 'center'
  }
]

export const slotThead = (vm, slotOption = {}) => [
  {
    title: '名称',
    key: 'name',
    width: slotOption.nameWidth || 100,
    align: 'center'
  },
  {
    title: '说明',
    key: 'desc',
    render: (h, params) => {
      const { desc } = params.row

      if (typeof desc === 'string') {
        return h('span', {}, desc)
      }
      return desc(h, vm)
    }
  }
]
